﻿using System;
using System.Collections.Generic;
using Godot;

namespace kemocard.Scripts.Enemy;

public static class EnemyFactory
{
    private static readonly Dictionary<string, Type> EnemyTypeDict = new()
    {
        { "1", typeof(E1) },
        { "bat_earth", typeof(BatEarth) },
        { "worm_earth", typeof(WormEarth) },
        { "slime_earth", typeof(SlimeEarth) },
        { "swan", typeof(Swan) },
        { "liz", typeof(LizEarth) },
        { "tutorial_pawn", typeof(TutorialPawn) },
    };

    /// <summary>
    /// 注册敌人脚本，需继承EnemyScript，重复注册会覆盖
    /// </summary>
    /// <param name="enemyId">Id</param>
    /// <param name="enemyType">脚本类</param>
    public static void RegisterEnemy(string enemyId, Type enemyType)
    {
        if (enemyType == typeof(EnemyScript))
        {
            EnemyTypeDict[enemyId] = enemyType;
        }
    }

    public static EnemyScript CreateEnemy(string enemyId)
    {
        if (EnemyTypeDict.TryGetValue(enemyId, out var enemyType))
        {
            return (EnemyScript)Activator.CreateInstance(enemyType);
        }

        GD.PrintErr($"无法找到敌人脚本, ID:{enemyId}");
        return null;
    }
}